import React,  {useState,useEffect}from 'react';
import './Property_overview.scss';
import Child from './Child';
import http from '../../utils/http';
import {observer} from 'mobx-react';
import store from '../../store/index'
const Project_management = () => { 
  const toTime = (value) => {
    let date = new Date(value)
    let y = date.getFullYear()  //获取年份
    let m = date.getMonth() + 1  //获取月份
    m = m < 10 ? "0" + m : m  //月份不满10天显示前加0
    let d = date.getDate()  //获取日期
    d = d < 10 ? "0" + d : d  //日期不满10天显示前加0
    return y + "-" + m + "-" + d

}
  // 获取正常运行设备
  useEffect(()=>{
    http({
      url:'/propertyOverview/numberOfEquipmentInNormal',
    }).then((res)=>{
      store.dongji.numberOfEquipmentInNormal=res.data
    })
  },[])
  // 获取年度累计缴费
  useEffect(()=>{
    http({
      url:'/propertyOverview/annualAccumulativePayment',
    }).then((res)=>{
      store.dongji.annualAccumulativePayment=res.data
    })
  },[])
  // 获取今日进出人数(人)
  useEffect(()=>{
    http({
      url:'/propertyOverview/numberOfPeopleEntering',
    }).then((res)=>{
      store.dongji.numberOfPeopleEntering=res.data
    })
  },[])
  // 今日进出车辆(辆)
  useEffect(()=>{
    http({
      url:'/propertyOverview/IncomingAndOutgoingToday',
    }).then((res)=>{
      store.dongji.IncomingAndOutgoingToday=res.data
    })
  },[])
  // 设备分类占比
  useEffect(()=>{
    http({
      url:'/propertyOverview/proportionOfDevicesByCategory',
    }).then((res)=>{
      console.log(res.data);
      let arr=res.data;
      let arr3=[]
      arr.forEach((v,i) => {
        let arr2=[]
       for(let key in v){
        arr2.push(v[key])
       }
       arr3.push(arr2)
      });
    console.log(arr3);
    })
  },[])
   // 物业缴费
   useEffect(()=>{
 
  },[])
    //获取访客数据
    useEffect(()=>{
      http({
          url:'/visitors/visitorsList',
          method:'post',
      }).then((res)=>{
          if(res.code==200){
              // console.log(res.data);
              let  arr=res.data.data.map((v,i)=>{
                  return {
                      key:v.visId, 
                      visId:v.visId,
                      visName:v.visName, //访客姓名
                      visPhone:v.visPhone, //联系方式
                      visType:v.visType == 0 ? '企业' : (v.visType == 1?'公寓':'其他' ), //造访类型
                      vireUnit:v.vireUnit, //造访单位
                      havCar:v.havCar,    //是否驾车
                      carNumber:v.carNumber, //车牌号码
                      leaveTime:toTime(v.leaveTime), //造访结束时间
                  }
              })
              store.dongji.visitor=arr;
              store.dongji.count=res.data.count
          }
        // console.log( store.dongji.visitor);
      })
  },[])

  return (
    <div className='overview'>
              <div>
                <Child></Child>
              </div>
    </div>
  
   
  );
};
export default observer(Project_management)